<template>
    <div class="video-container">
        <div class="poster" v-if="!isPlaying">
            <img class="poster-img" :src="detail.videoposter" />

            <div class="play-btn" @click="isPlaying = true">
                <img
                    class="icon-play"
                    :src="`${_oss_}images/mobile/case-detail/icon-play.png`"
                />
            </div>
        </div>
        <video
            :src="detail.introductionfile"
            autoplay
            controls
            controlslist="nodownload"
            v-else
        ></video>
    </div>

    <div class="tabs">
        <div
            class="tab-item"
            v-for="(item, index) in tabList"
            :key="item.value"
            :class="{
                active: tabActive === index,
            }"
            @click="tabActive = index"
        >
            {{ item.label }}
        </div>
    </div>

    <div class="introduce-container">
        <div class="top">
            <div class="title">{{ detail.name }}</div>

            <div class="cb">{{ detail.page_view }}人学过</div>

            <div class="btn-group">
                <div
                    class="btn btn-primary"
                    :class="{ disabled: !detail.url }"
                    @click="emits('onCaseView')"
                >
                    案例视频
                </div>
                <div class="btn btn-default" @click="emits('onCaseExperience')">
                    案例体验
                </div>
            </div>
        </div>

        <!-- 详情 -->

        <div class="details">
            <div class="cell-title">课程介绍</div>

            <div class="desc" v-html="detail.synopsiscontent || ''"></div>
        </div>
    </div>
</template>
<script setup>
const props = defineProps({
    detail: {
        type: Object,
        default: () => ({}),
    },
});
const emits = defineEmits(["onCaseView", "onCaseExperience"]);
const isPlaying = ref(false);

const tabActive = ref(0);
const tabList = reactive([
    {
        label: "简介",
        value: "introduce",
    },
    {
        label: "目录",
        value: "catalog",
    },
    {
        label: "评价",
        value: "discussion",
    },
]);
</script>
<style lang="scss" scoped>
.video-container {
    width: 100%;
    height: 190px;
    padding: 0 15px;

    .poster {
        width: 100%;
        height: 100%;
        position: relative;

        .poster-img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .play-btn {
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            background-repeat: no-repeat;
            background-position: center;
            margin: 0;
            background-color: rgba(0, 0, 0, 0.4);
            display: flex;
            align-items: center;
            justify-content: center;

            img {
                width: 50px;
                height: 50px;
            }
        }
    }

    video {
        width: 100%;
        height: 100%;
        background-color: #000;
    }
}

.tabs {
    width: calc(100% - 30px);
    display: flex;
    height: 46px;
    border-bottom: 1px solid #e8e9e9;
    margin: 0 auto;

    .tab-item {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 16px;

        &.active {
            position: relative;
            color: #ff3f29;

            &::after {
                content: "";
                position: absolute;
                bottom: 0;
                left: 50%;
                height: 3px;
                width: 60%;
                background-color: #ff3f29;
                transform: translate(-50%);
            }
        }
    }
}

.introduce-container {
    background-color: rgb(242, 244, 247);

    .top {
        padding: 15px;
        background-color: #fff;
        margin-bottom: 8px;

        .title {
            font-size: 18px;
            font-weight: 600;
            color: #333;
            line-height: 25px;
        }

        .cb {
            font-size: 12px;
            color: #999;
            line-height: 1.5em;
            margin: 8px 0;
        }

        .btn-group {
            margin-top: 15px;

            .btn {
                display: inline-flex;
                align-items: center;
                justify-content: center;
                width: 150px;
                height: 32px;
                font-size: 14px;
                cursor: pointer;

                &-default {
                    color: #666;
                    border: 1px solid #666;
                    margin-left: 20px;
                    box-sizing: border-box;

                    &:hover {
                        border: 1px solid #ff3f29;
                        color: #ff3f29;
                    }
                }

                &-primary {
                    background: #ff8000;
                    color: #fff;

                    &:hover {
                        background: #ee6600;
                    }
                }

                &.disabled {
                    color: #fff;
                    background-color: #ccc;
                    cursor: default;
                }
            }
        }
    }

    .details {
        background-color: #fff;

        .cell-title {
            position: relative;
            font-size: 16px;
            line-height: 22px;
            color: #333;
            padding: 15px;
            font-weight: bold;

            &::after {
                content: "";
                width: 5px;
                height: 13px;
                background: #ff3f29;
                position: absolute;
                left: 0;
                top: 50%;
                transform: translateY(-50%);
            }
        }

        .desc {
            color: #333;
            word-break: break-all;
            white-space: pre-wrap;
            font-size: 16px !important;
            font-family: "宋体" !important;
            line-height: 1.5em !important;
            margin-bottom: 20px;
            padding: 0 15px;

            :deep(*) {
                font-size: 16px !important;
                font-family: "宋体" !important;
                line-height: 1.5em !important;
            }

            :deep(img) {
                max-width: 100%;
                display: block;
            }
        }
    }
}
</style>
